package com.huike.web.controller.business;

import com.huike.business.domain.TbBusiness;
import com.huike.business.domain.dto.TbBusinessDto;
import com.huike.business.domain.vo.TbBusinessVo;
import com.huike.business.service.TbBusinessService;

import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/business")
@Slf4j
public class TbBusinessController extends BaseController {
    @Autowired
    private TbBusinessService tbBusinessService;
    /**
     * 条件分页查询
     */
    @GetMapping("/list")
    public TableDataInfo page(TbBusinessDto tbBusinessDto){
        startPage();
        List<TbBusinessVo> tbBusinessDtoList = tbBusinessService.page(tbBusinessDto);
        return  getDataTable(tbBusinessDtoList);
    }

    /**
     * 添加商机
     */
    @PostMapping
    public AjaxResult add(@RequestBody TbBusiness tbBusiness){
        int rows =tbBusinessService.add(tbBusiness);
        return  toAjax(rows);

    }
    /**
     * 根据Id查询信息
     */
    @GetMapping("{id}")
    public AjaxResult findById(@PathVariable Long id){
        log.info("根据Id查询信息:",id);
        TbBusiness tbBusiness = tbBusinessService.findById(id);
        return AjaxResult.success(tbBusiness);
    }

}
